<?php
/*错误记录*/
class cpError
{
	static public function getIp()
	{
		if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
		   $ip = getenv("HTTP_CLIENT_IP");
		else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
		   $ip = getenv("HTTP_X_FORWARDED_FOR");
		else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
		   $ip = getenv("REMOTE_ADDR");
		else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
		   $ip = $_SERVER['REMOTE_ADDR'];
		else
		   $ip = "unknown";
		return($ip);
	}
	static public function write($message)
	{
		
		if(!defined('CP_LOG_PATH'))
		{
			return false;//没有定义日志目录，则不记录
		}
		$log_path=CP_LOG_PATH;
		 if((!file_exists($log_path))||(!is_dir($log_path))) 
		 {
			//创建日志记录目录
			@mkdir($log_path,0755);
		 }
		 
		 if(substr($log_path, -1) != "/")    
		 {
			$log_path = CP_LOG_PATH."/";
		 }
		 $time=date('Y-m-d H:i:s');
		 $ip=self::getIp();
		 $destination =$log_path .date("y-m-d").".log";
       	 @error_log("{$time} | {$ip} | {$message}\r\n", 3,$destination);

	}
     static public function show($message)
    {
		//如果开启了日志记录，则写入日志
		if(defined('CP_LOG_ON')&&CP_LOG_ON)
		{
			self::write($message);
		}
		if(!defined('__APP__'))
		{	
			define('__APP__','/');
		}
		echo 
		'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
*{margin:0;padding:0}
body{
	font-family: "Microsoft Yahei", Verdana, arial, sans-serif;
	font-size:14px;
}
a{text-decoration:none;color:#174B73;}
a:hover{ text-decoration:none;color:#FF6600;}
.message{
	margin-left:auto;
	margin-right:auto;
	margin-top:20px;
	width:800px;
	font-size:16px;
	font-weight:bold;
	background-color: #FFFCAA;
	border: 1px solid #DFE7D0;
}
.message h1{ padding-top:8px;padding-left:10px;font-size:14px; color:#FE6600;}
.message .message_contents{ margin-top:20px; padding-left:15px;color:#FF0000;}
.message .footer{ margin-top:20px; margin-bottom:10px; padding-left:30px;font-size:14px; font-weight:normal;}
</style>
<title>温馨提示</title>
</head>

<body>
<div class="message">
	<h1>温馨提示</h1>
	<div class="message_contents">'.$message.'</div>
	<div class="footer">您可以选择 [ <A HREF="'.$_SERVER['PHP_SELF'].'">重试</A> ] [ <A HREF="javascript:history.back()">返回</A> ] 或者 [ <A HREF="'.__APP__.'">回到首页</A> ] </div>

</div>
</body>
</html>';
		exit;
    }
}
?>